<%--
  Created by IntelliJ IDEA.
  User: 康娜的小肥腿
  Date: 2020/3/25 0025
  Time: 15:42
--%>
<%@ page import="com.student.dao.StudentDao" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<jsp:useBean id="emp" class="com.student.model.Student"/>
<jsp:setProperty name="emp" property="*"/>

<%
    String hire_date = request.getParameter("hire_date"); // yyyy-MM-dd
    if (hire_date != null) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date hiredate = format.parse(hire_date);
        emp.setHiredate(hiredate);
    }

    boolean successful = new StudentDao().save(emp);
    if (successful) {
        // 只要是做insert,update,delete操作完成后都是使重定向
        response.sendRedirect(request.getContextPath() + "/1.jsp");
    } else {
        response.sendRedirect(request.getContextPath() + "/addForm.jsp");
    }

%>